#ifndef _WDS_GUN_H_
#define _WDS_GUN_H_

#include "wds_player.h"

#include "math/vec2.h"
#include "wds_bullet.h"

class WDSLifeObject;


class WDSGun
{
public:

	
	enum GUN_TYPES
	{
		GUN_TYPE_PISTOL,				// 10 bullets, 1 sec to shoot, 1 sec to reload

		GUN_TYPE_MEAN_MINIGUN,			// 120 bullets magazine, 14 secs to shoot , 4 sec to reload		
		GUN_TYPE_SUBMACHINE,			// 30 bullets magazine , 1 bullets at a time // 3 sec to shoot, 1 sec to reload
		GUN_TYPE_ASSAULT_RIFLE,			// 25 bullets magazine , 1 bullets at a time //  4 sec to shoot all , 2 sec to reload

		GUN_TYPE_SHOTGUN,				// 12 bullets magazine , 9-12 bullets at a time // 1 sec to shoot // 2 sec to reload
		GUN_TYPE_SAWED_OFF_SHOTGUN,		// 12 bullets magazine , 11 bullets at a time // 1 sec to shoot // 2 sec to reload
		GUN_TYPE_JACK_HAMMER,			// 16 bullets magaine // 3-4 bullets at a time // 3.5 sec to shoot all // 2 sec to reload		

		GUN_TYPE_GAUSS,					// 6 bullets magazine,  0.5 sec to shoot, 1 sec to reload 
		GUN_TYPE_GAUSS_SHOTGUN,			// 4 bullets magazine, 11 bullets at a time // 1.1 sec to shoot, 2 sec to reload 
		
		GUN_TYPE_ION_MINIGUN,			// 20 bullets magazine, 1 bullets at a time // 3 sec to shoot all// 2 sec to reload
		GUN_TYPE_ION_RIFLE,				// 8 bullets magazine, 1 bullets at a time // 0.5 sec to shoot // 2 sec to reload
		GUN_TYPE_ION_SHOTGUN,			// 10 bullets magazine, 8 bullets at a time // 1 sec to shoot // 2 sec to reload
		GUN_TYPE_ION_CANNON,			// 3 bullets magazine, 1 bullets at a time // 1 sec to shoot // 3 sec to reload

		GUN_TYPE_ROCKET_LAUCHER,		// 5 bullets magazine, 1 bullets at a time // 1 sec to shoot // 1.2 sec to reload
		GUN_TYPE_ROCKET_SEEKER,			// 6 bullets magaine, 1 bullets at a time // 4 sec to shoot, 1 sec to reload
		GUN_TYPE_ROCKET_MINIGUN,		// 16 bullets magaine, 1 bullets at a time // 3 sec to shoot, 1 sec to reload
		GUN_TYPE_ROCKET_MINI_SWARMERS,  // 1 bullet magazine , 5 bullets at a time // 1.5 sec to shoot // 1.5 sec to reload

		GUN_TYPE_FLAME_THROWER,			// 30 bullets magazine // 4 secs to shoot all , 2 sec to reload

		GUN_TYPE_PLASMA_MULTI,			// 8 bullets magazine , 5 bullets at a time, 0.5 sec to shoot , 1 sec to reload
		GUN_TYPE_PLASMA_MINIGUN,		// 30 bullets magazine , 1 bullet at a time, 4 sec to shoot all, 2 sec to reload
		GUN_TYPE_PLASMA_RIFLE,			// 20 bullets magazine , 1 bullet at a time, 7 sec to shoot all, 1 sec to reload
		GUN_TYPE_PLASMA_SHOTGUN,		// 8 bullets magazine , 15 bullet at a time, 0.5 sec to shoot, 3 sec to reload
		GUN_TYPE_PLASMA_CANNON,			// 3 bullets magazine , 1 bullet at a time, 1 sec to shoot, 2 sec to reload

		GUN_TYPE_PULSE,					// 16 bullets magaine , 2-2.5 secs to shoot	
		GUN_TYPE_SPLITTER,				//  
		
		GUN_TYPE_C,

	};


	struct GunUI
	{
		void			Init();
		void			Render(WDSGun* pGun, float Scale);
		void			Tick(WDSGun* pGun, float dt);

		
		ui::UISprite	m_UIBulletEmpty;
		ui::UISprite	m_UIBulletFull;	
		ui::UISprite	m_UIGun;

		
	};

		

	WDSGun(	GUN_TYPES Type, float ExtraAmmoPerc);
	~WDSGun();
		
	void							Render(const math::Vec2& PlayerPos, const math::Vec2& Offset, float Rotation, float Scale);
	void							RenderUI(float Scale) { m_GunUI.Render(this, Scale); };
	void							Tick(float dt);
	void							ShootTick(float dt, const WDSPlayer::Skill& PlayerSkill,  const math::Vec2& Offset);

	void							Shoot(
											WDSLifeObject* pShooter,
											float	SpeedBonus,
											const math::Vec2& ShootPos,														
											float Degree,	
											const math::Vec2& Offset,
											int SoundSFXIndex
											);
	void							SetFireBulletDuration(float Duration) { m_FireBulletDuration = Duration; };
		

protected:


	virtual void					ShootPrivate(	WDSLifeObject* pShooter,
													float	SpeedBonus,
													const math::Vec2& ShootPos,														
													float Degree,		
													const math::Vec2& Offset,
													int SoundSFXIndex);


	virtual void					OnBulletCreated(WDSBullet* pBullet);


	WDSBullet::BULLET_TYPES			GetBulletType() const;
	

	
	GUN_TYPES						m_Type;
	float							m_MoveSpeedDecreaseRatio;
	
	
	int								m_MinBulletCountAtSingleShot;
	int								m_MaxBulletCountAtSingleShot;
	int								m_BulletIndexOfMagazine;
	int								m_MagazineCount;
	float							m_ReloadTime;
	float							m_CurrentReloadDelay;
	
	float							m_BulletDelay;
	float							m_CurrentBulletDelay;

	float							m_InAccuracy;
	float							m_MaxInAccuracy;
	
	float							m_MinSpeedScale;
	float							m_MaxSpeedScale;
	float							m_FireBulletDuration;			// Fire(Noun) 
	WDSGun::GunUI					m_GunUI;

	ui::UISprite					m_SpriteGunThrust;
	float							m_GunThrustShowing;

	ui::UISprite					m_SpriteLaserSight;
	float							m_TimeSinceLastBullet;


};

class WDSGunPlasmaMulti : public WDSGun
{
public:

	WDSGunPlasmaMulti(float ExtraAmmoPerc): WDSGun(WDSGun::GUN_TYPE_PLASMA_MULTI, ExtraAmmoPerc ) {};

protected:
	virtual void					ShootPrivate(	WDSLifeObject* pShooter,
													float	SpeedBonus,
													const math::Vec2& ShootPos,														
													float Degree,
													const math::Vec2& Offset,
													int SoundSFXIndex);

};

class WDSGunION : public WDSGun
{
public :
	WDSGunION(GUN_TYPES Type, float ExtraAmmoPerc, int CountToBounce);

	void							SetCountToBounce(int Count) { m_CountToBounce = Count; };
protected:
	virtual void					OnBulletCreated(WDSBullet* pBullet);

	int								m_CountToBounce;

};

#endif

